﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace AJAX_learning.Chapter11
{
	public partial class p2 : System.Web.UI.Page
	{
		protected override void OnLoad(EventArgs e)
		{
			base.OnLoad(e);
			
			if (this.IsPostBack)
			{
				lblInfo.Text += "Page posted back.<br />";
			}
			else
			{
				lblInfo.Text += "Page created.<br />";
			}
			var testItem = (DateTime?)Cache["TestItem"];
			if (testItem == null)
			{
				lblInfo.Text += "Creating TestItem...<br />";
				testItem = DateTime.Now;
				lblInfo.Text += "Storing TestItem in cache ";
				lblInfo.Text += "for 30 seconds.<br />";
				Cache.Insert("TestItem", testItem, null,
				DateTime.Now.AddSeconds(30), TimeSpan.Zero);
			}
			else
			{
				lblInfo.Text += "Retrieving TestItem...<br />";
				lblInfo.Text += "TestItem is '" + testItem;
				lblInfo.Text += "'<br />";
			}
			lblInfo.Text += "<br />";
		}
	}
}